package com.rui1024.servlet;

import com.rui1024.dao.MenuDao;
import com.rui1024.dao.OrderDao;
import com.rui1024.dao.impl.MenuDaoImpl;
import com.rui1024.dao.impl.OrderDaoImpl;
import com.rui1024.pojo.Menu;
import com.rui1024.util.JDBCUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/homeServlet")
public class homeServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        request.setCharacterEncoding("utf-8");// 设置为统一编码

        OrderDao od = new OrderDaoImpl();
        JDBCUtil jdbcUtil = new JDBCUtil();
        Connection con = null;

        try {
            con = jdbcUtil.getCon();
            int listTotalSum= od.ordersSumTotal(con);

            if (listTotalSum<=200){
                String point="你的订单金额不足200,无法选择包间";
                request.setAttribute("point",point);
                request.setAttribute("homeselect","无");
            }else if (listTotalSum > 200 && listTotalSum<=500) {
                String point="你的订单金额不足500";
                request.setAttribute("point",point);
                request.setAttribute("homeselect","包间一");
            }else if (listTotalSum > 500 && listTotalSum<=1000) {
                String point="你的订单金额不足1000";
                request.setAttribute("point",point);
                request.setAttribute("homeselect","包间二");
            }else if (listTotalSum > 1000 && listTotalSum<=2000) {
                String point="你的订单金额不足2000";
                request.setAttribute("point",point);
                request.setAttribute("homeselect","包间三");
            }else {
                String point="你的订单金额充足";
                request.setAttribute("point",point);
                request.setAttribute("homeselect","包间四");
            }
            request.setAttribute("listTotalSum", listTotalSum);// 把数据存起来
            request.getRequestDispatcher("privateroom.jsp").forward(request, response);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                jdbcUtil.closeCon(con);
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }



}